package com.itheima.webserver.interceptor;

import com.itheima.commons.model.domain.Admin;


/**
 * 拿当前请求线程存储Token中对应的用户信息
 */
public class AdminThreadLocal {
    private static final ThreadLocal<Admin> threadLocal = new ThreadLocal<>();

    // 设置Admin到当前线程
    public static void set(Admin admin) {
        threadLocal.set(admin);
    }

    // 从当前线程获取Admin
    public static Admin getAdmin() {
        return threadLocal.get();
    }

    // 从当前线程删除Admin
    public static void remove() {
        threadLocal.remove();
    }

    // 获取Admin的id
    public static Long getUserId() {
        return threadLocal.get().getUid();
    }

}
